#!/usr/bin/python
# -*- coding: utf-8 -*-


import oauth
from binder import bind_api
from parsers import ModelParser


class QQAPI(object):
    """class for  QQ weibo API"""
    def __init__(self, consumer, access_token=None, \
                host='open.t.qq.com'):
        """constructor for QQAPI"""
        self.consumer = consumer
        self.access_token = access_token
        self.host = host
        self.parser = ModelParser()

    """oauth 1.0"""
    """/cgi-bin/request_token 获取request_token"""
    get_request_token = bind_api(
        url='/cgi-bin/request_token',
        method='GET',
        require_auth=True,
        ssl=True,
        data_format='string',
        data_type='token',
        allowed_params=['oauth_callback']
    )

    """/cgi-bin/access_token 获取access_token"""
    get_access_token = bind_api(
        url='/cgi-bin/access_token',
        method='GET',
        require_auth=True,
        ssl=True,
        data_format='string',
        data_type='token',
        allowed_params=['oauth_verifier']
    )

    """statuses 时间线相关"""
    """statuses/home_timeline 主页时间线"""
    home_timeline_statuses = bind_api(
        url='/api/statuses/home_timeline',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'pageflag', 'pagetime', 'reqnum']
    )

    """statuses/public_timeline 广播大厅时间线"""
    public_timeline_statuses = bind_api(
        url='/api/statuses/public_timeline',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'pos', 'reqnum']
    )

    """statuses/user_timeline 其他用户发表时间表"""
    user_timeline_statuses = bind_api(
        url='/api/statuses/user_timeline',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'pageflag', 'pagetime', 'reqnum',\
                        'lastid', 'name']
    )

    """statuses/mentions_timeline 提到我的时间线"""
    mentions_timeline_statuses = bind_api(
        url='/api/statuses/mentions_timeline',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'pageflag', 'pagetime', 'reqnum',\
                        'lastid']
    )

    """statuses/ht_timeline 话题时间线"""
    ht_timeline_statuses = bind_api(
        url='/api/statuses/ht_timeline',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'httext', 'pageflag', 'pageinfo', \
                        'reqnum']
    )

    """statuses/broadcast_timeline 我发起的时间线"""
    broadcast_timeline_statuses = bind_api(
        url='/api/statuses/broadcast_timeline',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'pageflag', 'pagetime', 'reqnum', \
                        'lastid']
    )

    """statuses/special_timeline 特别收听人发表时间线"""
    special_timeline_statuses = bind_api(
        url='/api/statuses/special_timeline',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'pageflag', 'pagetime', 'reqnum']
    )

    """t 微博相关"""
    """/t/show 获取一条微博数据"""
    show_t = bind_api(
        url='/api/t/show',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='weibo',
        allowed_params=['format', 'id']
    )

    """/t/add 发送一条微博"""
    add_t = bind_api(
        url='/api/t/add',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'content', 'clientip', 'jing', 'wei']
    )

    """/t/del 删除一条微博"""
    del_t = bind_api(
        url='/api/t/del',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'id']
    )

    """/t/re_add 转播一条微博"""
    re_add_t = bind_api(
        url='/api/t/re_add',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'content', 'reid', 'clientip', \
                        'jing', 'wei']
    )

    """/t/reply 回复一条微博"""
    reply_t = bind_api(
        url='/api/t/reply',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'content', 'reid', 'clientip', 'jing',\
                        'wei']
    )

    """/t/add_pic 发表带图片的微博"""
    add_pic_t = bind_api(
        url='/api/t/add_pic',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'content', 'clientip', 'jing', 'wei'],
        additional_params=['pic'],
        multipart_form =True
    )

    """/t/re_count 转播数和点评数"""
    re_count_t = bind_api(
        url='/api/t/re_count',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='tcount',
        allowed_params=['format', 'ids', 'flag']
    )

    """/t/re_list 获取单条微博的转发或点评列表"""
    re_list_t = bind_api(
        url='/api/t/re_list',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='timeline',
        allowed_params=['format', 'flag', 'rootid', 'pageflag', \
                        'pagetime', 'reqnum', 'twitterid']
    )

    """/t/comment 点评一条微博"""
    comment_t = bind_api(
        url='/api/t/comment',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'content', 'clientip', 'jing', \
                        'wei', 'reid']
    )

    """/t/add_music 发表音乐微博"""
    add_music_t = bind_api(
        url='/api/t/add_music',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'content', 'clientip', 'jing', \
                        'wei', 'url', 'title', 'author']
    )

    """/t/add_video 发表视频微博"""
    add_video_t = bind_api(
        url='/api/t/add_video',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='id',
        allowed_params=['format', 'content', 'clientip', 'jing', \
                        'wei', 'url']
    )

    """/t/getvideoinfo 获取视频信息"""
    getvideoinfo_t = bind_api(
        url='/api/t/getvideoinfo',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='video',
        allowed_params=['format', 'url']
    )

    """user 账户相关"""
    """/user/info 获取自己的账户信息"""
    info_user = bind_api(
        url='/api/user/info',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='user',
        allowed_params=['format']
    )

    """/user/update 更新用户信息"""
    update_user = bind_api(
        url='/api/user/update',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format', 'nick', 'sex', 'year', 'month', \
                        'day', 'countrycode', 'provincecode', 'citycode',\
                        'introduction']
    )

    """/user/update_head 更新用户头像"""
    update_head_user = bind_api(
        url='/api/user/update_head',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format'],
        additional_params=['pic'],
        multipart_form=True
    )

    """/user/other_info 获取其他人资料"""
    other_info_user = bind_api(
        url='/api/user/other_info',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='user',
        allowed_params=['format', 'name']
    )

    """Friends 关系链相关"""
    """friends/fanslist 我的听众列表"""
    fanslist_friends = bind_api(
        url='/api/friends/fanslist',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='fan',
        allowed_params=['format', 'reqnum', 'startindex']
    )

    """friends/idollist 我收听的人的列表"""
    idollist_friends = bind_api(
        url='/api/friends/idollist',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='fan',
        allowed_params=['format', 'reqnum', 'startindex']
    )

    """friends/blacklist 黑名单列表"""
    blacklist_friends = bind_api(
        url='/api/friends/blacklist',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='fan',
        allowed_params=['format', 'reqnum', 'startindex']
    )

    """friends/speciallist 特别收听列表"""
    speciallist_friends = bind_api(
        url='/api/friends/speciallist',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='fan',
        allowed_params=['format', 'reqnum', 'startindex']
    )

    """friends/add 收听某个用户"""
    add_friends = bind_api(
        url='/api/friends/add',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format', 'name']
    )

    """friends/del 取消收听某个用户"""
    del_friends = bind_api(
        url='/api/friends/del',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format', 'name']
    )

    # 需要通过审核
    """friends/addspecial 特别收听某个用户"""
    addspecial_friends = bind_api(
        url='/api/friends/addspecial',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format', 'name']
    )

    # 需要通过审核
    """friends/delspecial 取消特别收听某个用户"""
    delspecial_friends = bind_api(
        url='/api/friends/delspecial',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format', 'name']
    )

    # 需要通过审核
    """friends/addblacklist 添加某个用户到黑名单"""
    addblacklist_friends = bind_api(
        url='/api/friends/addblacklist',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format', 'name']
    )


    # 需要通过审核
    """friends/delblacklist 从黑名单删除某个用户"""
    delblacklist_friends = bind_api(
        url='/api/friends/delblacklist',
        method='POST',
        require_auth=True,
        data_format='json',
        data_type='basic',
        allowed_params=['format', 'name']
    )

    """friends/check 检测是否是我的听众或收听的人"""
    check_friends = bind_api(
        url='/api/friends/check',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='relation',
        allowed_params=['format', 'names', 'flag']
    )
    
    """friends/user_fanslist 其他账户的听众列表"""
    user_fanslist_friends = bind_api(
        url='/api/friends/user_fanslist',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='fan',
        allowed_params=['format', 'reqnum', 'startindex', 'name']
    )

    """friends/user_idollist 其他账户的收听列表"""
    user_idollist_friends = bind_api(
        url='/api/friends/user_idollist',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='fan',
        allowed_params=['format', 'reqnum', 'startindex', 'name']
    )
    
    """friends/user_speciallist 其他账户的特别收听列表"""
    user_speciallist_friends = bind_api(
        url='/api/friends/user_speciallist',
        method='GET',
        require_auth=True,
        data_format='json',
        data_type='fan',
        allowed_params=['format', 'reqnum', 'startindex', 'name']
    )
